package org.example.core.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.example.Util.UserUtil;
import org.example.api.ComfyuiApi;
import org.example.core.Dto.Text2ImageCanelResponseDto;
import org.example.core.Dto.Text2ImageResDto;
import org.example.core.Dto.Text2ImageResponseDto;
import org.example.core.Dto.common.PageRequestDto;
import org.example.core.Dto.common.Result;
import org.example.core.Service.RedisService;
import org.example.core.Service.Text2ImageService;
import org.example.core.pojo.ComfyuiTask;
import org.example.core.pojo.UserResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/api/authed/1.0/t2i")
public class TextToImageController {


    @Autowired
    private Text2ImageService text2ImageService;
    @PostMapping("/propmt")
    public Result<Text2ImageResponseDto> prompt(@RequestBody Text2ImageResDto dto) throws TemplateException, IOException {
        Text2ImageResponseDto text2ImageResponseDto = text2ImageService.TextToImage(dto);
        return Result.ok(text2ImageResponseDto);
    }

    @PostMapping("/list")
    public Result<Result<List<UserResult>>> list(@RequestBody PageRequestDto dto) {
        return Result.ok(Result.ok(text2ImageService.list(dto.getPageNum(), dto.getPageSize()))) ;
    }
    @PostMapping("/canel")
    public Result canel(@RequestBody Text2ImageCanelResponseDto text2ImageResponseDto) throws IOException {

        return Result.ok(text2ImageService.canel(text2ImageResponseDto));
    }
    @PostMapping("/proprity")
    public Result<Object> proprity(@RequestBody Text2ImageCanelResponseDto text2ImageResponseDto) throws TemplateException, IOException {

        return text2ImageService.proprity(text2ImageResponseDto);
    }

}
